package com.haiheng.voiceandbook

import android.content.Context
import android.content.Intent
import android.util.Log
import com.tencent.bugly.Bugly.applicationContext

/**
 *
 * @Des: 自定义的异常处理器
 * @Author: hwz
 * @Date:2023/10/30 0030
 * @Version: 1.0
 */
class CustomExceptionHandler(private val context: Context) : Thread.UncaughtExceptionHandler {
    override fun uncaughtException(thread: Thread, throwable: Throwable) {

        Log.e("CustomExceptionHandler",throwable.toString())
        // 例如重新启动应用
        try {
            val intent = Intent(context, MainActivity::class.java)
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
            context.startActivity(intent)
            Log.e("CustomExceptionHandler","结束当前进程")
            // 结束当前进程
            android.os.Process.killProcess(android.os.Process.myPid())
            System.exit(0)
        }catch (ex:Exception){
            Log.e("CustomExceptionHandler","重新启动异常："+ex)
        }

    }
}
